<template>
  <div class="filter-param">
    <div class="webheart classbox">
      <div
        class="class-wrap clearfix"
        v-if="zylxObj.isShow == 0 && showCourseType && type != 5"
      >
        <div :class="['fl', 'className', 'acitve' + type]">
          <h2 class="fl class-titile">{{ zylxObj.name || '资源类型' }}：</h2>
          <p
            v-for="v in sourceType"
            :key="v.id"
            :class="{ acitve: sourceActive == v.value }"
            @click="handleSourceType(v.value)"
          >
            {{ v.name }}
          </p>
        </div>
      </div>
      <div class="class-wrap clearfix" v-if="zyflObj.isShow == 0">
        <div :class="['fl', 'className', 'acitve' + type]">
          <h2 class="fl class-titile">{{ zyflObj.name || '资源分类' }}：</h2>
          <p :class="{ acitve: labelActive == '' }" @click="handleLabel()">
            全部
          </p>
          <p
            :class="{ acitve: labelActive == v.id }"
            v-for="v in labelData"
            :key="v.id"
            @click="handleLabel(v.id)"
          >
            {{ v.name }}
          </p>
        </div>
      </div>
      <div
        class="class-wrap clearfix"
        v-if="pxccObj.isShow == 0"
        v-show="type == 1 || type == 5"
      >
        <div :class="['fl', 'className', 'acitve' + type]">
          <h2 class="fl class-titile">{{ pxccObj.name || '培训层次' }}：</h2>
          <p :class="{ acitve: trainActive == '' }" @click="handleTrain()">
            全部
          </p>
          <p
            :class="{ acitve: trainActive == v.id }"
            v-for="v in trainingLevel"
            :key="v.id"
            @click="handleTrain(v.id)"
          >
            {{ v.name }}
          </p>
        </div>
      </div>
      <div class="class-wrap clearfix" v-if="tgdwObj.isShow == 0">
        <div :class="['fl', 'className', 'acitve' + type]">
          <h2 class="fl class-titile">{{ tgdwObj.name || '提供单位' }}：</h2>
          <p :class="{ acitve: deptActive == '' }" @click="handleDept()">
            全部
          </p>
          <p
            :class="{ acitve: deptActive == v.id }"
            v-for="v in deptData"
            :key="v.id"
            @click="handleDept(v)"
          >
            {{ v.name }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {
  openApiSysTrainingLevelQuery,
  openApiSysDeptQuery,
  openApiSysLabelQuery,
} from '@/api/openApi'
import { LIBRARY } from '@/utils/config.js'
import homeConfig from '@/mixins/homeConfig'
import courseCreate from '@/mixins/courseCreate'
export default {
  mixins: [courseCreate, homeConfig],
  data() {
    return {
      type: this.$route.meta.type,
      curLibrary: {},
      sourceActive: '',
      trainActive: '',
      deptActive: '',
      labelActive: '',
      listQuery: {
        page: 1,
        limit: 99,
      },
      sourceType: [
        { id: 0, name: '全部', value: '' },
        { id: 1, name: '校本资源', value: '1' },
        { id: 2, name: '校外资源', value: '2' },
      ],
      trainingLevel: [],
      deptData: [],
      labelData: [],
      zylxObj: {}, // 资源类型
      zyflObj: {}, // 资源分类
      pxccObj: {}, // 培训层次
      tgdwObj: {}, // 提供单位
    }
  },
  watch: {
    $route() {
      this.type = this.$route.meta.type
      this.curLibrary = LIBRARY.filter((v) => v.type == this.type)[0]
      this.getList()
    },
  },
  mounted() {
    this.curLibrary = LIBRARY.filter((v) => v.type == this.type)[0]
    this.zylxObj = this.showModuleObj('zylx')
    this.zyflObj = this.showModuleObj('zyfl')
    this.pxccObj = this.showModuleObj('pxcc')
    this.tgdwObj = this.showModuleObj('tgdw')
    this.getList()
  },
  methods: {
    getList() {
      openApiSysTrainingLevelQuery(this.listQuery).then((res) => {
        this.trainingLevel = res.data.data
      })
      openApiSysDeptQuery({ pId: 0 }).then((res) => {
        let { data } = res.data
        if (data && data.length) {
          this.deptData = data[0].childList.filter((v) => v.type && v.type == 1)
        }
      })
      openApiSysLabelQuery({ type: this.type, labelType: 1 }).then((res) => {
        this.labelData = res.data.data
      })
    },
    handleTrain(v) {
      this.trainActive = v || ''
      this.$emit('e-courseList', { trainingLevel: v })
    },
    handleDept(v) {
      this.deptActive = v ? v.id : ''
      this.$emit('e-courseList', { sourceUnit: this.deptActive })
    },
    handleLabel(v) {
      this.labelActive = v || ''
      this.$emit('e-courseList', { labelValue: v })
    },
    handleSourceType(v) {
      this.sourceActive = v || ''
      this.$emit('e-courseList', { sourceType: v })
    },
  },
}
</script>
<style scoped lang="scss">
.filter-param {
  width: 100%;
  padding-top: 55px;
  padding-bottom: 10px;
  background: #f3f9fa;
  .classbox {
    .class-wrap {
      position: relative;
      width: 100%;
      .class-titile {
        float: left;
        margin-right: 10px;
        font-size: 18px;
        color: #333;
        font-weight: bold;
        line-height: 30px;
      }
      .className {
        float: left;
        text-align: center;
        p {
          float: left;
          min-width: 50px;
          text-align: center;
          height: 30px;
          line-height: 30px;
          padding: 0 10px;
          font-size: 16px;
          color: #333;
          margin-right: 20px;
          border: 0 none;
          border-radius: 5px;
          cursor: pointer;
          margin-bottom: 15px;
          transition: all 0.3s;
          &:hover,
          &.acitve {
            background: #06a2c9;
            color: #fff;
          }
        }
      }
      .acitve1 {
        p {
          &:hover,
          &.acitve {
            background: #06a2c9;
            color: #fff;
          }
        }
      }
      .acitve2 {
        p {
          &:hover,
          &.acitve {
            background: #0659a7;
            color: #fff;
          }
        }
      }
      .acitve3 {
        p {
          &:hover,
          &.acitve {
            background: #3d815a;
            color: #fff;
          }
        }
      }
      .acitve4 {
        p {
          &:hover,
          &.acitve {
            background: #e67c00;
            color: #fff;
          }
        }
      }
      .acitve5 {
        p {
          &:hover,
          &.acitve {
            background: #cc8690;
            color: #fff;
          }
        }
      }
    }
  }
}
</style>